/**
 * Created by lixiaoping on 15/10/23.
 */
require.config(require_config);

define([
    'jquery',
    'common',
    'ready',
    'template',
    'model',
    'dialog'
], function ($, common, ready, template, Model, dialog) {
    var index = function () {
        this.init();
    };
    index.prototype = {
        init: function () {
            loading();
            this.fetch();
            this.event();
        },

        fetch: function () {
            this.model = new Model({
                container: 'main-view',
                template: 'order-tpl',
                tag_name: 'div',
                url: _global.url.api + 'site/subsidy_amount',
                callback: function () {
                    loaded();
                }
            });
            this.model.fetch();
        },

        event: function () {
            var _this = this;
            console.log(this.model.data);
            var opt_teller = function (_data, dialogObj2) {
                if (_data.withdraw_info) {
                    var data = {};
                    if (new Model({
                            url: _global.url.api + 'site/subsidy_amount',
                            data: data
                        }).post()) {
                        //_this.fetch();
                        location.href = '/site/amount/withdraws';
                    }
                    dialogObj2.close();
                } else {
                    location.href = '/site/amount/withdraw_info';
                }
            }
            /**
             * 添加事件
             */
            $('body').on('click', '.item-teller', function (e) {
                e.preventDefault();
                var _data = _this.model.data;
                var dialogObj = dialog({
                    title: '提现',
                    content: template('site-teller-tpl', _data),
                    width: 500,
                    modal: true,
                    okValue: _data.withdraw_info ? '申请提现' : '前往填写',
                    ok: function () {
                        dialogObj.close();
                        var dialogObj2 = dialog({
                            content: '请稍等 ,系统正在处理...',
                            width: 200,
                            modal: true
                        });
                        dialogObj2.show();
                        setTimeout(function () {
                            opt_teller(_data, dialogObj2);
                        }, 500);
                    }, cancel: function () {
                    }
                });
                dialogObj.show();
            });
        }
    };

    new index();

});